<template>
  <view>
    <cu-custom bgColor="bg-gradual-green" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">静态评估</block>
    </cu-custom>
    <scroll-view scroll-x class="bg-white nav">
      <view class="flex text-center" style="font-size: 30upx; font-weight: 555;">
        <view class="cu-item flex-sub" :class="index==TabCur?'text-green cur':''" v-for="(item,index) in taball" :key="index"
          @tap="tabSelect" :data-id="index">
          {{item.name}}
        </view>
      </view>
    </scroll-view>

    <form v-if="TabCur == 0">
      <view class="quan">
        <view class="tianj" style="background-image: url(../../static/BasicsBg.png);">
          <view class="jingt">
            添加静态评估后，可以更好的定制合适您的训练
          </view>
          <view class="pingg" @click="jump" data-src='/pagesA/Static_evaluation/Static_evaluation_problem'>
            + 添加静态评估
          </view>
        </view>
        <view class="cu-bar bg-white" style="border-bottom: 1px solid #ddd;">
          <!-- <view class="action">
						
					</view> -->
          <view class="action" style="position: absolute;right: 0;">
            <text class="text-df margin-right-sm">仅看我的</text>
            <switch :class="shadow?'checked':''" color="#39B54A"></switch>
          </view>
        </view>
        <view v-if="datas1.length">
          <uni-swipe-action>
            <uni-swipe-action-item v-for="(item,index) in datas1" :options="item.options" :key="item.id" @change="swipeChange"
              @click="swipeClick($event, item.id)">
              <view class="u-f-ajc u-f-jsb" style="width: 100%;border-bottom: 1px solid #ddd;" @click="jump" :data-src='"/pagesA/Static_evaluation/Static_evaluation_list_details_page?id="+item.id'>
                <view class="zuo">
                  静态评估
                </view>
                <view class="you u-f-ajc">
                  <view class="shuz" style="border-right: 2upx solid #ddd;">
                    {{item.userName}}
                  </view>
                  <view class="shuz">
                    {{item.createTime}}
                  </view>
                  <view class="cuIcon-right"></view>
                </view>
              </view>
            </uni-swipe-action-item>
          </uni-swipe-action>
        </view>
        <image v-else class="zanw" src="/static/11.png" mode=""></image>
      </view>
    </form>

    <form v-if="TabCur == 1">
      <view class="tianj" style="background-image: url(../../static/BasicsBg.png);">
        <view class="jingt">
          添加体态对比后，可以更好的定制合适您的训练
        </view>
        <view class="pingg" @click="jump" data-src='/pagesA/Static_evaluation/Static_evaluation_list_details'>
          + 添加体态对比
        </view>
      </view>
      <view v-if="datas2.length">
        <uni-swipe-action>
          <uni-swipe-action-item v-for="(item,index) in datas2" :options="item.options" :key="item.id" @change="swipeChange"
            @click="swipeClick($event, item.id)">
            <view class="u-f-ajc u-f-jsb" style="width: 100%;border-bottom: 1px solid #ddd; padding: 30rpx 50rpx;"
              @click="jump" :data-src='"/pagesA/Static_evaluation/Assessment_results?id="+item.id'>
              <view>
                {{item.name}}
              </view>
              <view style="text-align: right;font-size: 24rpx;">
                <view style="margin-bottom: 10rpx;">
                  {{item.createTime}}
                </view>
                <view>
                  {{item.userName}}
                </view>
              </view>
            </view>
          </uni-swipe-action-item>
        </uni-swipe-action>
      </view>
      <image v-else class="zanw" src="/static/11.png" mode=""></image>
    </form>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        shadow: false,
        assessment: [],
        id: '',
        user: '',
        TabCur: 0, //默认tab选中项
        scrollLeft: 0,
        taball: [{
            name: '静态评估',
            index: 0,
          },
          {
            name: '体态对比',
            index: 1,
          },
        ],
        datas1: [],
        datas2: [],
      };
    },
    onLoad: function(e) {
      this.user = uni.getStorageSync("phyUser");
      if (e.id) this.id = e.id;
      else this.id = this.user.userId;
    },
    onShow() {
      this.getData(this.id);
      this.getData2(this.id);
    },
    methods: {
      swipeChange(e) {
        console.log('返回：', e);
      },
      swipeClick(e, id) {
        let {
          content
        } = e
        if (content.text === '删除') {
          uni.showModal({
            title: '提示',
            content: '是否删除',
            success: (res) => {
              console.log('用户点击了删除', res, id)
              this.deleteServer(id)
              if (res.confirm) {} else if (res.cancel) {
                console.log('用户点击取消');
              }
            }
          });
        }
      },
      async deleteServer(staticEvaId) {
        let urls = this.TabCur ? '/coach/body/deleteContrastBodyStateById?bodyStateId=' :
          '/coach/body/deleteBodyStaticEvaluationById?staticEvaId='
        uni.showLoading({
          title: "正在删除..."
        })
        let {
          data: {
            result
          }
        } = await this.$myRuquest({
          url: urls + staticEvaId,
          method: "DELETE",
        })
        if (result == 200) {
          uni.showToast({
            title: '删除成功~',
            icon: "success",
            duration: 1000
          });
          this.TabCur ? this.getData2(this.id) : this.getData(this.id)
        }
        uni.hideLoading();
      },


      async getData(memberId) {
        let {
          data: {
            datas
          }
        } = await this.$myRuquest({
          url: "/coach/body/getBodyStaticEvaluationList",
          data: {
            memberId,
          }
        })
        this.datas1 = datas;
        let siwpers = {
          options: [{
            text: '删除',
            style: {
              backgroundColor: 'rgb(255,58,49)'
            }
          }],
          sid: 0,
          content: 'item1'
        }
        this.datas1.forEach((item, index) => {
          Object.assign(item, siwpers)
        })
      },
      async getData2(memberId) {
        let {
          data: {
            datas
          }
        } = await this.$myRuquest({
          url: "/coach/body/getContrastBodyStateList",
          data: {
            memberId,
          }
        })
        this.datas2 = datas;
        let siwpers = {
          options: [{
            text: '删除',
            style: {
              backgroundColor: 'rgb(255,58,49)'
            }
          }],
          sid: 0,
          content: 'item1'
        }
        this.datas2.forEach((item, index) => {
          Object.assign(item, siwpers)
        })
      },
      tabSelect(e) {
        this.TabCur = e.currentTarget.dataset.id;
        this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
      },
      jump(e) {
        let url = e.currentTarget.dataset.src;
        if (url.indexOf('Static_evaluation_list_details' != -1)) {
          uni.setStorageSync("item", '');
          uni.setStorageSync("title", '');
          uni.setStorageSync("list", '');
        }
        uni.navigateTo({
          url
        });
      },
    }
  }
</script>

<style>
  .quan {
    background: #ffffff;
  }

  .tianj {
    height: 400upx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .jingt {
    font-size: 30upx;
    font-weight: 555;
    color: #ffffff;
    padding: 40upx;
  }

  .pingg {
    font: 24upx;
    font-weight: 555;
    background: #128de6;
    border-radius: 40upx;
    padding: 20upx;
    color: #ffffff;
  }

  .zuo {
    font-size: 26upx;
    font-weight: 555;
    padding: 20upx;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .you {
    padding: 20upx;
    font-size: 24upx;
    color: #cecece;
  }

  .shuz {
    padding: 10upx;
  }

  .zanw {
    width: 100%;
    height: 800upx;
  }
</style>
